﻿Imports System.Data
Imports System.Data.SqlClient

Public Class DComprador
    Inherits conexion
    Dim cmd As New SqlCommand

    Public Function insertarcomprador(ByVal item As Entidades.Ecomprador) As Boolean
        Try
            conectado()
            'iniciartransacion()
            cmd = New SqlCommand("insertar_comprador")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@dni", item.dnipers)
            cmd.Parameters.AddWithValue("@nombreyapellido", item.nomyapepers)
            cmd.Parameters.AddWithValue("@edad", item.edadpers)
            cmd.Parameters.AddWithValue("@fecha_nac", item.fechanacpers)
            cmd.Parameters.AddWithValue("@dom", item.dompers)
            cmd.Parameters.AddWithValue("@tel1", item.tel1pers)
            cmd.Parameters.AddWithValue("@tel2", item.tel2pers)
            cmd.Parameters.AddWithValue("@loca", item.codlocpers)
            cmd.Parameters.AddWithValue("@email", item.emailpers)
            cmd.Parameters.AddWithValue("@tipopago", item.tipopagocompra)

            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If



        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()
        End Try
    End Function

    Public Function llenarcombo() As DataTable
        Try
            conectado()
            cmd = New SqlCommand("llenarcombolocalidad")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

    Public Function busquedaxnombrecomp(ByVal nombre As String) As DataTable
        Try
            conectado()
            cmd = New SqlCommand("busquedadenomcomp")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn
            cmd.Parameters.AddWithValue("@nombreyapellido", nombre)


            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function
    Public Function busquedaxdnicomp(ByVal dni As String) As DataTable
        Try
            conectado()
            cmd = New SqlCommand("busquedadednicomp")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn
            cmd.Parameters.AddWithValue("@dni", dni)


            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

End Class
